﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ObjectSync.Util
{
    public static class StringEncode
    {
        //Econde the string to transmition and to fit in the protocol
        public static String EconcodeToTransmit(Object obj)
        {
            if (obj == null) return "NULL";

            var s = obj.ToString();

            string res = s.Replace("$", "%1");
            res = res.Replace("#", "%2");
            res = res.Replace("|", "%3");
            res = res.Replace("%", "%4");

            return res;
        }
        //Econde the string to transmition and to fit in the protocol
        public static String DeconcodefromTransmission(String message)
        {
            if (message == null) return "NULL";

            var s = message;

            string res = s.Replace("%1", "$");
            res = res.Replace("%2", "#");
            res = res.Replace("%3", "|");
            res = res.Replace("%4", "%");

            return res;
        }
    }
}
